package com.studio49.exmple.common.SMSUtils;

import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class LoadProperties {
	/**
	 * 通过key值获取配置文件中value值
	 * 
	 * @param key
	 *            配置文件中key值
	 * @return
	 */
	public static String readValue(String key) {
		/*String fileName = "sms.properties";*/
		Properties props = new Properties();
		InputStream in = null;
		String value = "";
		try {
			Resource resource =new ClassPathResource("sms.properties");
			in = resource.getInputStream();
			/*in = LoadProperties.class.getResourceAsStream(fileName.toString());*/
			props.load(in);
			value = props.getProperty(key);
			return value;
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				in.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return value;
	}
}
